#include <iostream>

#include "util/arguments.h"

#include "mve/imagefile.h"
#include "mve/imagetools.h"

#include "cimgwrapper.h"

#include "featurematcher.h"
#include "eightpoint.h"

/* -------------------------------------------------------------- */

int main (int argc, const char * argv[])
{
    /* Setup argument parser. */    
    util::Arguments args;
    args.set_exit_on_error(true);
    args.set_nonopt_maxnum(2);
    args.set_nonopt_minnum(2);
    args.set_usage("Usage: fbundler IMAGE1 IMAGE2");
    args.parse(argc, argv);
    
    std::string file1 = args.get_nth_nonopt(0);
    std::string file2 = args.get_nth_nonopt(1);
    
    if (file1.empty() || file2.empty() )
    {
        args.generate_helptext(std::cerr);
        std::cerr << "Error: Input file omitted" << std::endl;
        return 1;
    }
    
    
    std::cout << file1 << " " << file2 << std::endl;
    
    /* Load input images */
    mve::ByteImage::Ptr img1(mve::image::load_file(file1));
    mve::ByteImage::Ptr img2(mve::image::load_file(file2));
    
    FeatureMatcher fm;
    fm.set_images(img1, img2);
    std::vector<FeatureMatch> matches = fm.match_features_surf();

	CImgWrapper cw;
	cw.visualize_feature_matches(file1, file2, matches);
	
	std::vector<math::Vec2f> fpoints;
	std::vector<float> scales;
	fm.get_features(fpoints, scales);
	cw.visualize_features(file1, fpoints, scales);
	
	EightPoint ep(&matches);
	ep.estimate_matrix();
    
    std::cout << " Finished !! " << std::endl;
    return 0;
}

/* -------------------------------------------------------------- */